package com.mrs.controller;

import com.mrs.common.ResponseResult;
import com.mrs.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * description: ArticleController
 * date: 2022/8/5 22:36
 * author: MR.孙
 */
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    // @GetMapping("/list")
    // public List<Article> test(){
    //     return articleService.list();
    // }


    //查询热门文章，封装成ResponseResult返回
    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList(){
        return articleService.hotArticleList();
    }


    /**
     * @description:  查询文章列表
     * @param pageNum
     * @param pageSize
     * @param categoryId
     * @return: com.mrs.common.ResponseResult
     * @author: MR.孙
     * @date: 2022/8/6 23:15
    */
    @GetMapping("/articleList")
    public ResponseResult articleList(Integer pageNum,Integer pageSize,Long categoryId){
        return articleService.articleList(pageNum,pageSize,categoryId);
    }

    //获取文章详情
    @GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable("id") Long id){
        return articleService.getArticleDetail(id);
    }

    //当更新浏览量时去更新redis数据
    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }


}
